package com.example.bookstore.utils;


import com.example.bookstore.mapper.UserRoleMapper;
import com.example.bookstore.service.BookService;
import com.example.bookstore.service.BookUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class CheckRoleUtil {

    @Autowired
    BookUserService userService;

    private static BookUserService userService1;
    @PostConstruct
    public void init2(){
        userService1 = this.userService;
    }

    @Autowired
    UserRoleMapper roleMapper;

    public static UserRoleMapper roleMapper1;
    @PostConstruct
    public void init(){roleMapper1 = this.roleMapper; }

    public boolean CheckRole(String[] key){
        String roleName =null;

            try{
                roleName = roleMapper1.SelectRoleById(userService1.getCurrentUser().getuserRole());
            }catch (Exception e){
                e.printStackTrace();
                return false;
            }
            System.out.println("************************");
            System.out.println(key);

        for (String i:key) {
            if (roleName.equals(i)){
                return true;
            }else {
                continue;
            }
        }
        return false;
    }

}
